﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="OptimumInfra.ViewData" %>
<%@ Import Namespace="System.Collections.Generic" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
     <div id="step">
        <span><%=ViewData["message"] %></span>
     </div>
  <script type="text/javascript">
        var Product = new Array();
    </script>
   <div id="resourceContent">
  <table width="650px;" style="margin-top: 10px;">
  <tr>
    <th width="80px;">Item</th>
     <th>Description</th>
     <th width="120px;">Amount</th>
      <th width="80px;">Price/Month</th>
  </tr>
    <%
        int i = 1;
     foreach (var resource in (ViewData["resources"] as IEnumerable<ViewDataResource>))
     {
            %>           
               <tr>
                <td>
                <div id="resource<%=i %>"><%=resource.Name%></div>
                <div id="resourceid<%=i %>" style="display:none;"><%=resource.Id%></div>
                </td>
                <td><%=resource.Description%></td>
                 <td>
                <select name="amount<%=resource.Id %>" id="amount<%=resource.Id %>">
                <option value="">------</option>
                <%
     Dictionary<int, string> option = resource.PricePerAmount;
     foreach (KeyValuePair<int, string> a in option)
     {
                        
                 %>
                 <option value="<%=a.Value %>"><%= a.Key%></option>
                
                 <% } 
            
                    %>
                 </select>
                 <div id="unit<%=i %>" style="float: right; margin-right: 10px;"><%=resource.Unit %></div>
                </td>
                 <td><div id="price<%=i %>"></div></td>
               </tr> 
               
            <%
                i++;
     }
            
         %>
         <tr>
            <td colspan="4">          
                <button onclick="javascript:addResourceToCart();" class="button btn-cart" title="Add to Cart" type="button"><span><span>Add to Cart</span></span>
                </button>          
             </td>
          </tr> 
     </table>
         <div class="templateBottom">
             <a href="/Template/?step=1">Back</a>
             <a href="/ServiceSupport/?step=3">Next</a>
             <a href="/Account/">Finish</a>
         </div>
         
     </div>
     <script type="text/javascript">
         $("select").change(function () {

             var i = 1;
             $("select option:selected").each(function () {
                 var str = "";
                 str += $(this).val();
                 if (str != "") {
                     var temp = str.split("_");
                     var test = "#unit" + i;
                     var unit = $(test).text();
                     $("#price" + i).text(temp[0] + "$/" + unit);
                 }
                 else
                     $("#price" + i).text("");
                 i++;
             });

         })
        .change();
</script>    
<script type="text/javascript">
     function addResourceToCart() {
         var i = 1;
         $("select option:selected").each(function () {
             var str = "";
             str += $(this).val();
             if (str != "") {
                 var div = "#resource" + i.toString();
                 var name = $(div).text();
                 var temp = str.split("_");
                 var id = parseInt($("#resourceid" + i.toString()).text());
                 var price = parseInt(temp[0]);
                 var quatity = parseInt($(this).text());
                 var Product = new Array();
                 Product[0] = id;                         //id
                 Product[1] = 2;                         //type
                 Product[2] = name;              //name
                 Product[3] = quatity;                         //quality
                 Product[4] = price;                       //price
                 Product[5] = Product[3] * Product[4];   //total    
                 list.add(Product);
             }
             i++;
         });
     }
  </script>

</asp:Content>